home *** CD-ROM | disk | FTP | other *** search
- Path: sdrc.com!thor!scjones
- From: scjones@thor.sdrc.com (Larry Jones)
- Newsgroups: comp.lang.c
- Subject: Re: Problem with arrays
- Date: 31 Jan 1996 18:37:12 GMT
- Organization: SDRC Engineering Services
- Distribution: world
- Message-ID: <4eocso$a98@info1.sdrc.com>
- References: <4ejtia$6id@sifon.cc.mcgill.ca> <4en2ig$6af@gryphon.phoenix.net>
- NNTP-Posting-Host: thor.sdrc.com
-
- In article <4en2ig$6af@gryphon.phoenix.net>, brucew@phoenix.net (Bruce Wedding) writes:
- > C does not explicitly initialize arrays unless they are defined
- > global. You will have to zero out the array. You can use a loop
- > or the memset function. I think the loop is a little safer,
- > though maybe not as fast.
-
- While C doesn't initialize auto arrays, it allows you to do so. So the
- best thing to do is just:
-
- int letters[100] = {0};
-
- (If there are fewer initializers than array elements, the rest of the
- elements are initialize to 0, which is just what we want in the case.
- If you wanted to initialize it to something other than 0, you'd have to
- specify all 100 initializers.)
-
- As for using a loop versus memset, the loop is more flexible since you
- can initialize to any value at all, but for initializing to 0 both are
- equally safe since an integer 0 is required to be all bits zero (this
- is NOT true for floating point zeros or null pointers, however).
- ----
- Larry Jones, SDRC, 2000 Eastman Dr., Milford, OH 45150-2789 513-576-2070
- larry.jones@sdrc.com
- Oh, now don't YOU start on me. -- Calvin
-